﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using PersianLocalization;
using Telerik.WinControls.UI.Localization;

namespace TelerikForms.PL
{
    public partial class CopyBankForm : Telerik.WinControls.UI.RadForm
    {
        public CopyBankForm()
        {
            InitializeComponent();
            RadGridLocalizationProvider.CurrentProvider = new PersianRadGridLocalizationProvider();
        }

        private void addRowButton_Click(object sender, EventArgs e)
        {
            bankDGV.AllowAddNewRow = ! bankDGV.AllowAddNewRow;
        }

        private void BankForm_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable bankDT = new DataTable();
                ChequeManagement.BLL.BLLBankFactory bllBankObj = new ChequeManagement.BLL.BLLBankFactory();
                bllBankObj.GetAll(bankDT);

                bankDGV.DataSource = bankDT;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void deleteRowButton_Click(object sender, EventArgs e)
        {
            try
            {
                GridViewDataRowInfo dataRowInfo = bankDGV.CurrentRow as GridViewDataRowInfo;
                if (dataRowInfo != null)
                {
                    int bankID = (int)dataRowInfo.Cells["bankIDCol"].Value;
                    ChequeManagement.BLL.BLLBankFactory bllBankObj = new ChequeManagement.BLL.BLLBankFactory();
                    bllBankObj.Remove(bankID);

                    bankDGV.Rows.Remove(dataRowInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void bankDGV_CommandCellClick(object sender, EventArgs e)
        {
            try
            {
                if (bankDGV.CurrentRow.Cells["bankNameCol"].Value.ToString() != "")
                {
                    ChequeManagement.BLL.BLLBank bankObj = new ChequeManagement.BLL.BLLBank();
                    bankObj.BankID = (int)bankDGV.CurrentRow.Cells["bankIDCol"].Value;
                    bankObj.BankName = (string)bankDGV.CurrentRow.Cells["bankNameCol"].Value;

                    ChequeManagement.BLL.BLLBankFactory bankFactory = new ChequeManagement.BLL.BLLBankFactory();
                    bankFactory.Edit(bankObj, bankObj.BankID);
                }
                else
                {
                    MessageBox.Show("لطفا نام بانک را وارد نمایید");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
